package com.cy.pj.goods.controller;

import com.cy.pj.goods.pojo.Goods;
import com.cy.pj.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goods/")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @GetMapping("doFindGoods")
    public List<Goods> doFindGoods(){
        return goodsService.findGoods();
    }

    @RequestMapping("doDeleteById/{id}")
    public String doDeleteById(@PathVariable Integer id) {
        goodsService.deleteById(id);
        return "delete ok";
    }

    @PostMapping("doSaveGoods")
    public String doSaveGoods(@RequestBody Goods entity) {
        goodsService.saveGoods(entity);
        return "save ok";
    }

    @PostMapping("doUpdateGoods")
    public String doUpdateGoods(@RequestBody Goods entity) {
        goodsService.updateGoods(entity);
        return "update ok";
    }

    @GetMapping("doFindById/{id}")
    public Goods doFindById(@PathVariable("id") Integer id) {
        return goodsService.fingById(id);
    }

}
